using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.IO;

namespace SellAvi.Model
{
    [Table("AvitoImages")]
    public partial class AvitoImage
    {
        public AvitoImage()
        {
            IsMainImage = false;
        }

        public int Id { get; set; }

        [StringLength(4000)]
        public string LocalFileName { get; set; }

        [StringLength(4000)]
        public string RemoteFileUrl { get; set; }

        [StringLength(4000)]
        public string Width { get; set; }

        [StringLength(4000)]
        public string Height { get; set; }

        [StringLength(4000)]
        public string FileSize { get; set; }

        public int AvitoProduct_Id { get; set; }

        [NotMapped]
        public string LocalImageFile
        {
            get
            {
                if (LocalFileName != null && File.Exists("images/" + LocalFileName))
                    return Path.GetFullPath("images/" + LocalFileName);
                if (RemoteFileUrl != null)
                {
                    return RemoteFileUrl;
                }
                return null;
            }
        }

        public bool IsMainImage { get; set; }

        public virtual AvitoProduct AvitoProduct { get; set; }
    }
}
